class Solution {
public:
    int minimumDeletions(string word, int k) {

        unordered_map<char,int> has;
        vector<pair<int,char>> arr;
        for(int i=0;i<word.size();++i){

            has[word[i]]++;
        }
        for(auto& e:has){

            arr.push_back({e.second,e.first});
        }
        int ret=0x3f3f3f3f;
        for(int i=0;i<arr.size();++i){

            int a=arr[i].first;
            char ar=arr[i].second;
            int sum=0;
            for(int j=0;j<arr.size();++j){

                if(ar==arr[j].second){

                    continue;
                }
                if(arr[j].first<a){

                    sum+=arr[j].first;
                }
                else if(arr[j].first>a+k){

                    sum+=arr[j].first-a-k;
                }
            }
            ret=min(ret,sum);
        }


        return ret;
    }
};
